package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/29 12:44
 */
public class LS64 {
    public int minPathSum(int[][] grid) {
        int x = grid.length;
        int y = grid[0].length;

        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                if (i == 0 && j==0){
                    continue;
                }
                if (i == 0) {
                    grid[i][j] = grid[i][j-1] + grid[i][j];
                }
                if (j==0) {
                    grid[i][j] = grid[i][j] + grid[i-1][j];
                }
                if (j!=0 && i != 0) {
                    grid[i][j] = grid[i][j] + Math.min(grid[i-1][j],grid[i][j-1]);
                }
            }
        }


        return grid[x-1][y-1];
    }
}
